package org.keyyond.ms.commonservice.service.impl;

import org.keyyond.ms.commonservice.dao.SDBDUserDao;
import org.keyyond.ms.commonservice.model.SDBDUser;
import org.keyyond.ms.commonservice.service.SDBDUserService;
import org.keyyond.ms.core.util.Constant;
import org.keyyond.ms.core.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import net.sf.json.JSONObject;

@Service
public class SDBDUserServiceImpl implements SDBDUserService{
	
	@Autowired
	private SDBDUserDao sdbdUserDao;

	@Override
	public int getAllUsersCount(SDBDUser user) {
		// TODO Auto-generated method stub
		return sdbdUserDao.getAllUsersCount(user);
	}

	@Override
	public Page<SDBDUser> selectAllByPage(JSONObject dataJson) {
		SDBDUser user = (SDBDUser) JsonUtil.jsonTBean(dataJson.getString("user"), SDBDUser.class);
		int startRows = dataJson.getInt(Constant.PAGE_STARTROW);
		int pageSizes = dataJson.getInt(Constant.PAGE_PAGESIZE);
		PageHelper.startPage(startRows, pageSizes);
		return sdbdUserDao.selectAllByPage(user);
	}

	@Override
	public SDBDUser selectByUsernameAndPassword(SDBDUser user) {
		// TODO Auto-generated method stub
		return sdbdUserDao.selectByUsernameAndPassword(user);
	}

	@Override
	public int getUserCountByUsername(String userName) {
		// TODO Auto-generated method stub
		return sdbdUserDao.getUserCountByUsername(userName);
	}

	@Override
	public int addUser(SDBDUser user) {
		// TODO Auto-generated method stub
		return sdbdUserDao.insert(user);
	}

	@Override
	public int deleteUserBySeqno(String seqno) {
		// TODO Auto-generated method stub
		return sdbdUserDao.deleteUserBySeqno(seqno);
	}

	@Override
	public SDBDUser selectByPrimaryKey(String seqno) {
		// TODO Auto-generated method stub
		return sdbdUserDao.selectByPrimaryKey(seqno);
	}

}
